Skip to content

Ensure SocketStream recalculates the timeout on each read #1299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 7, 2024

Conversation

rozza
Copy link
Member

@rozza rozza commented Jan 23, 2024

@rozza rozza requested a review from vbabanin January 23, 2024 12:06
try {
ByteBuf buffer = bufferProvider.getBuffer(numBytes);
try {
int totalBytesRead = 0;
byte[] bytes = buffer.array();
while (totalBytesRead < buffer.limit()) {
int readTimeoutMS = (int) operationContext.getTimeoutContext().getReadTimeoutMS();
if (readTimeoutMS > 0) {
Copy link
Member

@vbabanin vbabanin Jan 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems If the timeout has already expired, readTimeoutMS can be 0. In this case, if socket.setSoTimeout was previously set to 100ms, the socket timeout still remains at 100ms, leading to repeated 100ms blocks, which could exceed the intended timeout.

I suggest that getReadTimeoutMS should throw an exception if timeoutMs has already expired.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@rozza rozza requested a review from vbabanin February 1, 2024 10:15
Copy link
Member

@vbabanin vbabanin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@rozza rozza merged commit bbc2d10 into mongodb:CSOT Feb 7, 2024
@rozza rozza deleted the JAVA-5298 branch February 7, 2024 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants